﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;

namespace Dapper.Moon
{
    public class DbFactory
    {
        private DbFactory() { }

        public static IDapperMoon Create(string nameOrConnectionString, DbType dbType = DbType.SqlServer)
        {
            if (string.IsNullOrWhiteSpace(nameOrConnectionString))
            {
                throw new Exception("nameOrConnectionString the parameter is empty");
            }
            if (nameOrConnectionString.IndexOf('=') != -1)
            {
                return new DapperMoon(nameOrConnectionString, dbType);
            }
            ConnectionStringSettings cs = ConfigurationManager.ConnectionStrings[nameOrConnectionString];
            if (cs == null)
            {
                throw new Exception("configuration information not found");
            }
            return new DapperMoon(cs.ConnectionString, dbType);
        }
    }
}
